from flask_wtf import FlaskForm
import wtforms
from wtforms.validators import DataRequired, Email, Length, EqualTo


class loginForm(FlaskForm):
    account = wtforms.StringField(render_kw={"class": "tex", "placeholder": "账号"},
                                  validators=[wtforms.validators.data_required()])
    password = wtforms.PasswordField(render_kw={"class": "tex tex2", "placeholder": "密码"},
                                     validators=[wtforms.validators.data_required()])
    remenber_me = wtforms.BooleanField(
        render_kw={'class': "che", 'value': "1", 'id': "remember"})
    submit = wtforms.SubmitField(render_kw={"class": "but"})


class registerForm(FlaskForm):
    user_id = wtforms.StringField(validators=[DataRequired('need'), Length(6, 20)],
                                  render_kw={'class': "form-control-sm"})
    user_name = wtforms.StringField(validators=[DataRequired('need'), Length(6, 20)],
                                    render_kw={'class': "form-control-sm"})
    user_password1 = wtforms.PasswordField(validators=[DataRequired('need'), Length(6, 20)],
                                           render_kw={'class': "form-control-sm"})
    user_password2 = wtforms.PasswordField(
        validators=[DataRequired('need'), Length(6, 20), EqualTo('user_password1', message="两次密码输入不一致")],
        render_kw={'class': "form-control-sm"})
    user_truename = wtforms.StringField(validators=[Length(0, 6)],
                                        render_kw={'class': "form-control-sm"})
    user_sex = wtforms.SelectField(label='性别', choices=((1, '男'), (2, '女')), coerce=int, validators=[],
                                   render_kw={'class': "form-check form-check-inline"})
    user_email = wtforms.StringField(validators=[DataRequired(), Email()], render_kw={'class': "form-control-sm"})
    user_phonenumber = wtforms.StringField(validators=[DataRequired(), Length(11, 20)],
                                           render_kw={'class': "form-control-sm"})
    user_birthday = wtforms.DateField(render_kw={'class': "form-control-sm"})
    user_profession = wtforms.StringField(validators=[Length(0, 20)], render_kw={'class': "form-control-sm"})
    user_units = wtforms.StringField(validators=[Length(0, 40)], render_kw={'class': "form-control-sm"})
    user_location = wtforms.StringField(validators=[Length(0, 40)], render_kw={'class': "form-control-sm"})
    submit = wtforms.SubmitField(render_kw={'class': "btn btn-primary main_button1"})


class edictInfoForm(FlaskForm):
    user_truename = wtforms.StringField(label='真实姓名', validators=[Length(0, 6)])
    user_sex = wtforms.SelectField(label='性别', choices=((1, '男'), (2, '女')), coerce=int)
    user_email = wtforms.StringField(label='Email', validators=[DataRequired(), Email()])
    user_phonenumber = wtforms.StringField(label='电话号码', validators=[DataRequired(), Length(11, 20)])
    user_birthday = wtforms.DateField(label='生日', render_kw={'class': "form-control-sm"})
    user_profession = wtforms.StringField(label='专业', validators=[Length(0, 20)])
    user_units = wtforms.StringField(label='工作单位', validators=[Length(0, 40)])
    user_location = wtforms.StringField(label='通信地址', validators=[Length(0, 40)])
    user_about = wtforms.TextAreaField(label='关于我', validators=[Length(0, 128)])
    submit = wtforms.SubmitField('submit')


class postForm(FlaskForm):
    passage_title = wtforms.StringField(label='文章标题', validators=[DataRequired("标题不应为空")])
    passage_body = wtforms.TextAreaField('文章内容')
    submit = wtforms.SubmitField('提交')
